import {IMock} from './i-mock';
import {MockConfigItem} from '../../entity/mock-config-item';

export class DateMock implements IMock {
    getBaseTypeMockConfigDisplay(mockConfigItem: MockConfigItem): string {
        if (mockConfigItem.mockType === 1) {
            return '@now(YYYY-MM-dd HH:dd:ss)';
        }
        return `"${mockConfigItem.value}"`;
    }

    onSave(mockConfigItem: MockConfigItem): boolean {
        const DATE_TIME_PATTERN = /^\d{4}-\d{1,2}-\d{1,2}\s+\d{2}:\d{2}:\d{2}$/;
        if (mockConfigItem.mockType === 0 && !DATE_TIME_PATTERN.test(mockConfigItem.value)) {
            return false;
        }
        return true;
    }
}
